<template>
  <div class="form-widget form-custom-son-table">
    <x-proxy-form-item
      :isInTable="widget.isInTable"
      :showRequired="showRequired"
      :label="widget.label"
      :validatorRules="validatorRules"
      :validateKey="validateKey"
      :validateInfo="validateInfo"
    >
      <div class="parameterPageMobileAmendment">
        <div class="list">

          <ul class="item">
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">标题</span>
                </div>
                <div style="width: 75%">
              <span
                class="item-single-value">{{'PETG-合同变更-' + formData[getUuidByName('申请人')][0].username + '-' + formData[getUuidByName('申请时间')]}}</span>
                </div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">业务实体</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('业务实体')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">客户名称</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('客户名称')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">变更原因</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('变更原因')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #e4f3fc;">
                  <span class="item-single-title">变更内容</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('变更内容')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">合同有效期起</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('合同有效期起')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">合同有效期止</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('合同有效期止')]}}</span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">销售类型</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('销售类型')][0].name}}
                  </span></div>
              </div>
            </li>
            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">包装方式</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">
                   {{ formData[getUuidByName('包装方式')][0].name}}
                  </span></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">付款条件</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('付款条件')]}}</span></div>
              </div>
            </li>


            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">数量合计</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('数量总计(吨)')]}}</span></div>
              </div>
            </li>

            <li class="item-single">
              <div style="display: flex;justify-content: center;align-items: stretch;height: 100%;">
                <div style="width: 25%;background-color: #f5a623;">
                  <span class="item-single-title">含税合计</span></div>
                <div style="width: 75%">
                  <span class="item-single-value">{{formData[getUuidByName('含税合计')]}}</span></div>
              </div>
            </li>

          </ul>
          <div class="son-table">
            <ul class="son-list-single">
              <li class="th">产品线</li>
              <li class="th">牌号</li>
              <li class="th">等级</li>
              <li class="th">数量</li>
              <li class="th">成交单价</li>
            </ul>

            <div class="son-table-body">
              <template v-for="(item,index) in childrenData">
                <ul class="tr">
                  <li class="thv">PETG</li>
                  <li class="thv">{{ item[getChildUuidByName('牌号')][0].name }}</li>
                  <li class="thv">{{ item[getChildUuidByName('等级')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('合同变更后数量')] }}</li>
                  <li class="thv">{{ item[getChildUuidByName('成交单价')] }}</li>
                </ul>
              </template>
            </div>
          </div>
        </div>
      </div>
    </x-proxy-form-item>
  </div>
</template>

<script>
import FormWidgetConfigMixin from '@/mixin/form-widget.mixin'
export default {
  name: 'ContractChange',
  mixins: [FormWidgetConfigMixin],
  components: {},
  data: function () {
    return {
      dictMap:{
        'YORN':{
          'Y':'是',
          'N':'否'
        },
        'TYPE':{
          'BO_CUS':'商机客户',
          'TS_CUS':'交易客户'
        },
        'PETGTYPE':{
          'PETG':'PETG',
          'PET':'PET'
        },
        'SHIPVIA':{
          'a_self_p': '汽运自提',
          'a_arrive': '汽运送到',
          'o_arrive': '海运送到',
          'fob_o': 'FOB海运',
          'fca_o': 'FCA海运',
          'rail_auto':'铁陆联运',
          'expressage':'快递'
        }

      },
      mainData:{},
      childrenData:[]
    }
  },
  computed: {},
  created() {
    this.getData()
  },
  methods: {
    getData(){
       this.mainData = {}
       this.childrenData = this.formData[this.getTableUuidByName('合同明细')]

    },
    getDownloadUrl(url){
      const {$store, $base64} = this;
      const tenantId = $store?.state?.tenantModule?.currentOrg?.id;
      const token = $store?.state?.authModule?.token;
      const tokenBase64 = $base64.encode(
        JSON.stringify({
          xdaptenantid: tenantId,
          xdaptoken: token
        })
      );
      return url.replace("http://apaas-dev.crcchem.com/chem-crcchem-oms","").replace("http://apaas.crcchem.com/chem-crcchem-oms","") + `&token=${tokenBase64}`
    },
    downloadFile(item){
      let ur = this.getDownloadUrl(item.url) //url 参数 包含 file token
      let uuid = '&uuid='+this.getUuidByName('附件')
      let download = '&download=download'
      let formId = '&fromId='+this.globalData.formId
      let url = ur+download+formId+uuid
      window.APaaSSDK.context.globalVueContext.$root.$download({
        url: url,
        method: 'GET',
        //  responseType: 'blob',
        disableSuccessMsg: true,

      }).then((resp) => {
        console.log("下载成功")
      }).catch((r) => {
        console.error(r)
      })
    },

    // 根据自开发组件label获取对应表单子表tableUuid
    getTableUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.componentType === 'FORM_WIDGET_SON_TABLE') {
          tempUuid = value.uuid
        }
      })
      return tempUuid },
    // 根据自开发组件label获取对应表单 子表uuid
    getChildUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid },
    // 根据自开发组件label获取对应表单 主表uuid
    getUuidByName(name) {
      let tempUuid = ''
      this.formEngine.formDataControl.componentMap.forEach((value, key) => {
        if (value.label === name && !value.tableUuid) {
          tempUuid = value.uuid
        }
      })
      return tempUuid
    }
  }
}
</script>

<style lang="scss">

.form-custom-son-table {

  .parameterPageMobileAmendment {
    width: 100vw;
    height: auto;

    .list {
      height: 100%;
      overflow: visible;
      padding: 0;
    }
    .item-single{
      margin: 0 !important;
    }

    .item-single-value {
      width: 100%;
      word-break: break-all;
      white-space: normal;
      margin-left: 5px;
    }

    .item-single-title {
      width: 100%;
      font-weight: 900;
      background-color: #f5a623;
      color: #fff !important;
    }

    .item {
      margin: 0;
      padding: 0;

      li {
        list-style: none;
        border: 1px solid #dcdfe6;

        span {
          padding: 8px 0 8px 0;
          color: #555;
        }

        span:first-child {
          display: inline-block;


          border-right: 1px solid #dcdfe6;
        }
      }

      li + li {
        border-top: none;
      }

      li:last-child {
        border-radius: 0 0 4px 4px
      }
    }

    .son-table {
      height: auto;
      border-top: #dcdfe6 1px solid;
      border-left: #dcdfe6 1px solid;
      border-bottom: #dcdfe6 1px solid;
      padding: 0;
      margin: 0 auto;
      margin-top: 10px;
      font-size: 12px;
      overflow: hidden;

      .th {
        color: #fff;
        border-right: 1px solid #d7d7d7;
      }
      .thv{
        color: #555555;
        border-right: 1px solid #d7d7d7;
      }

      .son-list-single {
        width: 100%;
        display: grid;
        grid-template-columns: 1fr 1fr 1fr 1fr 1fr 18px;
        text-align: center;
        list-style: none;
        line-height: 2.6rem;
        background-color: #f5a623;
      }

      .son-table-body {
        overflow: hidden;

        .tr {
          width: 100%;
          display: grid;
          grid-template-columns: 1fr 1fr 1fr 1fr 1fr 18px;
          text-align: center;
          list-style: none;
          line-height: 2.6rem;
          border-bottom: 1px solid #dcdfe6;
        }
      }
    }


  }
}
</style>
